﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using System.Collections.Generic;
using Sebarf.ProcessChains.Interfaces;
using Sebarf.Services.Interfaces;
using Utils;

#endregion

namespace Sebarf.ProcessChains {
	/// <summary>
	/// The default implementation of the process chain manager service. Process chain management itself 
	/// is outsourced to the process chain manager service.
	/// </summary>
	public class ProcessChainManagerService : Service, IProcessChainExecutorService, IProcessChainRegisterService,
											  IProcessChainLocatorService {
		#region Public Properties

		/// <summary>
		/// The process chain manager.
		/// </summary>
		public ProcessChainManager Manager { get; private set; }

		#endregion

		#region Public Methods

		public ProcessChainManagerService() {
			Manager = new ProcessChainManager();
		}

		#endregion

		#region Private Methods

		#endregion

		#region Private Fields

		#endregion

		#region IProcessChainExecutorService Members

		/// <summary>
		/// Processes an object by applying the corret chain.
		/// </summary>
		/// <typeparam name="TToHandle"></typeparam>
		/// <param name="o"></param>
		/// <returns></returns>
		public object Process<TToHandle>(TToHandle o) {
			return Manager.Process(o);
		}

		#endregion

		#region IProcessChainLocatorService Members

		/// <summary>
		/// Returns all process chains,
		/// EACH STEP IS THE ROOT OF A CHAIN!
		/// </summary>
		/// <returns></returns>
		public IList<IProcessStep> GetProcessChains() {
			return Manager.GetRegisteredProcesses();
		}

		#endregion

		#region IProcessChainRegisterService Members

		/// <summary>
		/// Adds a chain.
		/// </summary>
		/// <param name="processStep">The first step of the chain</param>
		public void RegisterProcessChain(IProcessStep processStep) {
			Manager.RegisterProcessStep(processStep);
		}

		#endregion
	}
}